package com.backstage.base.service;

import com.backstage.base.mapper.UserMapper;
import com.backstage.base.models.User;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
@Component
public class UserService {
    @Autowired
    UserMapper userMapper;
    public void addUser(Integer id,String username, Integer age, boolean sex, float balance, String regTime,String pwd) {
        userMapper.insertUserRecord(id,username,age,sex,balance,regTime,pwd);
    }

    public void deleteUserById(Integer id) {
        userMapper.deleteFromUser(id);
    }

    public void updateUser(Integer id, String username, Integer age, boolean sex, float balance, String regTime, String pwd) {
        userMapper.updateUser(id,age,sex,balance,username,pwd,regTime);
    }

    public User queryById(Integer id){
        return userMapper.queryById(id);
    };

    public List<User> queryAllUser() {
        return userMapper.getUserList();
    }

//    public PageInfo<User> queryAllUserByPage(Integer pageNo, Integer pageSize) {
//        PageHelper.startPage(pageNo,pageSize);
//        PageInfo<User> pageInfo = (PageInfo<User>)userMapper.getUsersByPage(pageNo,pageSize);
//        return pageInfo;
//    }

    public List<User> find(String username){
        return userMapper.find(username);
    };

    public List<User> findUserByUser(String username,String pwd){
        return userMapper.findUserByUser(username,pwd);
    };
}
